﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Marmat.Foundation;

namespace example
{
    class MenuItemBuilder : IMenuItemBuilder
    {

        private readonly IMainForm mainForm;
        public MenuItemBuilder(IMainForm mainForm)
        {
            this.mainForm = mainForm;
        }

        /// <summary>
        /// 构建菜单
        /// </summary>
        /// <returns></returns>
        public void Builder(List<IMenu> menus)
        {
            menus.Add(new Menu { Name = "basics group", Text = "基础信息" });
            menus.Add(new Menu { Name = "user", Parent = "basics group", Text = "用户" });
        }

        /// <summary>
        /// 菜单点击事件
        /// </summary>
        public void ItemClick(IMenu menu)
        {

            if (mainForm.ContainsForm(menu.Name))
            {
                mainForm.SelectedFormName = menu.Name;
                return;
            }
            System.Windows.Forms.Form form;
            switch (menu.Name)
            {
                case "user":
                    form = new UserForm();
                    break;
                default:
                    throw new NotImplementedException();
            }
            if (form != null)
            {
                form.Name = menu.Name;
                mainForm.AddForm(form);
            }
        }
    }
}
